package com.yupi.springbootinit.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.yupi.springbootinit.model.entity.SalesOrder;
import com.yupi.springbootinit.model.vo.CountItemVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;

import java.util.List;

/**
 * 订单Mapper（SQL在XML）
 */
@Mapper
public interface SalesOrderMapper extends BaseMapper<SalesOrder> {

    SalesOrder selectByOrderNumber(@Param("orderNumber") String orderNumber);

    List<CountItemVO> countByStatus(@Param("orderType") String orderType);

    List<CountItemVO> countByUrgencyLevel(@Param("orderType") String orderType);

    List<SalesOrder> selectUpcomingDelivery(@Param("days") Integer days, @Param("orderType") String orderType);

    List<SalesOrder> selectOverdueOrders(@Param("orderType") String orderType);

    // 销售订单每日序列
    int initSalesOrderSeqIfAbsent(@Param("dateKey") String dateKey);

    int incrSalesOrderSeq(@Param("dateKey") String dateKey);

    // 研发订单每日序列
    int initRdoOrderSeqIfAbsent(@Param("dateKey") String dateKey);

    int incrRdoOrderSeq(@Param("dateKey") String dateKey);

    // 读取当前连接上的最后插入ID（对应上面UPDATE设置的值）
    Integer getLastInsertId();
}